<script setup>
defineProps({
  userInfo: {
    type: Object
  },
  dataList: {
    type: Array
  }
})
</script>
<template>
  <div class="messageArea">
    <div class="messageItem" v-for="(item, index) of dataList" :key="index">
      <div v-if="userInfo.unicode !== item.uid" class="leftChatBox">
        <div class="avatarBox">
          <img class="userAvatar" src="../../assets/images/avatar.jpg" alt="" />
          <span class="userName">{{ item.userName }}</span>
        </div>
        <span class="messageBox">{{ item.message }}</span>
      </div>
      <div v-else class="rightChatBox">
        <span class="messageBox">{{ item.message }}</span>
        <div class="avatarBox">
          <img class="userAvatar" src="../../assets/images/avatar.jpg" alt="" />
          <span class="userName">{{ item.userName }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<style>
.messageArea {
  padding: 20px;
  width: 100%;
  height: 400px;
  overflow-y: auto;

  .messageItem {
    &:nth-child(n + 2) {
      margin-top: 30px;
    }

    .leftChatBox,
    .rightChatBox {
      display: flex;
      align-items: flex-start;

      .avatarBox {
        position: relative;
        width: 40px;
        height: 40px;
        margin-right: 10px;

        .userAvatar {
          width: 100%;
          height: 100%;
          border-radius: 50%;
          border: 2px solid #007bff;
        }

        .userName {
          position: absolute;
          bottom: -20px;
          left: 50%;
          transform: translateX(-50%);
          white-space: nowrap;
          font-weight: bold;
          font-size: 14px;
          color: #333;
        }
      }

      .messageBox {
        max-width: 70%;
        padding: 8px 12px;
        border-radius: 16px;
        color: #333;
        background: #f1f1f1;
        word-break: break-all;
        text-align: left;
      }
    }

    .rightChatBox {
      justify-content: flex-end;
      align-items: flex-start;

      .avatarBox {
        margin-left: 10px;
        margin-right: 0;
      }

      .messageBox {
        background: #007bff;
        color: #fff;
        text-align: right;
      }
    }
  }
}
</style>
